/*
 * @Description:
 * @Version: 2.0
 * @Author: Mason
 * @Date: 2023-10-14 16:16:17
 * @LastEditors: Mason
 * @LastEditTime: 2023-10-14 16:34:42
 */
/*
 * @Description:
 * @Version: 2.0
 * @Author: Mason
 * @Date: 2023-10-14 16:16:17
 * @LastEditors: Mason
 * @LastEditTime: 2023-10-14 16:18:27
 */
package dao

import (
	"context"
	"time"

	"go.mongodb.org/mongo-driver/mongo"
	"go.mongodb.org/mongo-driver/mongo/options"
)

var db *mongo.Database

func InitMongodb(addr string, dbname string) {

	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
	defer cancel()
	client, err := mongo.Connect(ctx, options.Client().ApplyURI(addr))
	if err != nil {
		panic(err)
	}
	db = client.Database(dbname)

	User = &UserColl{collName: "user", coll: db.Collection("user")}

}
